#!/bin/bash

HTML_FILE=/home/liubin/taisan/doc/design/taisan_error_code_convention.html
declare -a GROUP

function get_rst_table()
{
	local start="$1"
	w3m -dump $HTML_FILE | sed -n "/$start/,/└/p" | sed -n '/┌/,/└/p' | sed '1,2d' | tee aa |
		grep '│' | fgrep -v '...' | tr -s '│' ' '
}

function init_group()
{
	local tmp=$(tempfile)
	get_rst_table 'Component code definition' > $tmp
	while read num desc ; do
		GROUP[num]='"'$desc'"'
	done < $tmp
	GROUP[0]=NULL
	rm $tmp
}

init_group

tmp=$(tempfile)
get_rst_table 'Error code examples' | fgrep -v SY000 >$tmp
while read code code2 msg ; do
	echo "{ $code, ${GROUP[code/1000]}," '"'$msg'" },'
done< $tmp
rm $tmp
